//
//  TripTableViewCell.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/20.
//  Copyright © 2018年 Lwx. All rights reserved.
//
#define Border 10
#define sideBtnH 40
#import "TripTableViewCell.h"

@interface TripTableViewCell()
@property (nonatomic, strong)UIButton * orderBtn;
@property (nonatomic, strong)UIImageView * tripImageView;
@property (nonatomic, strong)UIView * bgView;
@property (nonatomic, strong)UIImageView * locationImage;
@property (nonatomic, strong)UILabel * locationLab;
@property (nonatomic, strong)UILabel * contentLab;
@property (nonatomic, strong)UILabel * moneyLab;
@property (nonatomic, strong)UIButton * deleteBtn;
@property (nonatomic, strong)NSString * tid;
@end

@implementation TripTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = getColor(bgColor);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.orderBtn];
        [self.contentView addSubview:self.bgView];
        [self.bgView addSubview:self.tripImageView];
        [self.bgView addSubview:self.locationImage];
        [self.bgView addSubview:self.locationLab];
        [self.bgView addSubview:self.contentLab];
        [self.bgView addSubview:self.moneyLab];
        [self.contentView addSubview:self.deleteBtn];

    }return self;
}

- (UIButton *)orderBtn{
    if (!_orderBtn) {
        _orderBtn = [[UIButton alloc] init];
        [_orderBtn setCornerRadius:8];
        _orderBtn.layer.borderColor = [UIColor greenColor].CGColor;
        _orderBtn.layer.borderWidth = 1;
        [_orderBtn setTitle:@"已预订" forState:UIControlStateNormal];
        [_orderBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        _orderBtn.titleLabel.font = DEF_FontSize_14;
    }return _orderBtn;
}

- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        
    }return _bgView;
}

- (UIImageView *)tripImageView{
    if (!_tripImageView) {
        _tripImageView = [[UIImageView alloc] init];
        _tripImageView.backgroundColor = [UIColor redColor];
        
    }return _tripImageView;
}

- (UIImageView *)locationImage{
    if (!_locationImage) {
        _locationImage = [[UIImageView alloc] init];
        _locationImage.image = [UIImage imageNamed:@"yj_location"];
    }return _locationImage;
}

- (UILabel *)locationLab{
    if (!_locationLab) {
        _locationLab = [[UILabel alloc] init];
        _locationLab.font = DEF_FontSize_10;
        _locationLab.text = @"沈阳市沈阳市沈阳市沈阳市沈阳市";
//        _locationLab.backgroundColor = [UIColor yellowColor];
    }return _locationLab;
}

- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.font = DEF_FontSize_12;
        _contentLab.text = @"沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市沈阳市";
        _contentLab.numberOfLines = 0;
        _contentLab.lineBreakMode = 0;
//        _contentLab.backgroundColor = [UIColor greenColor];
    }return _contentLab;
}

- (UILabel *)moneyLab{
    if (!_moneyLab) {
        _moneyLab = [[UILabel alloc] init];
        _moneyLab.font = DEF_FontSize_14;
        _moneyLab.text = @"￥2300";
        _moneyLab.textColor = [UIColor redColor];
//        _moneyLab.backgroundColor = [UIColor purpleColor];
    }return _moneyLab;
}

- (UIButton *)deleteBtn{
    if (!_deleteBtn) {
        _deleteBtn = [[UIButton alloc] init];
        [_deleteBtn setCornerRadius:8];
        _deleteBtn.layer.borderColor = [UIColor redColor].CGColor;
        _deleteBtn.layer.borderWidth = 1;
        [_deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        [_deleteBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        _deleteBtn.titleLabel.font = DEF_FontSize_16;
        [_deleteBtn addTarget:self action:@selector(deleteBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _deleteBtn;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.bgView.frame = CGRectMake(SCREEN_WIDTH/4 + 2*Border, Border, SCREEN_WIDTH/2, self.contentView.height - 2 * Border);
    self.bgView.centerX = self.contentView.width/2;
    self.orderBtn.frame = CGRectMake(Border, Border, SCREEN_WIDTH/4 - 2*Border, sideBtnH);
    self.orderBtn.centerY = self.contentView.height / 2;
    self.deleteBtn.frame = CGRectMake(SCREEN_WIDTH - Border - self.orderBtn.width, self.orderBtn.top, self.orderBtn.width, self.orderBtn.height);
    
    self.tripImageView.frame = CGRectMake(Border / 2, Border / 2, self.bgView.width - 10, 100);
    self.locationImage.frame = CGRectMake(Border, self.tripImageView.bottom - Border - 5, 10, 10);
    self.locationLab.frame = CGRectMake(self.locationImage.right + 5, self.locationImage.top, self.tripImageView.width - self.locationImage.right - 5 - Border, self.locationImage.height);
    self.moneyLab.frame = CGRectMake(self.tripImageView.left, self.bgView.bottom - Border - 20 - 5, self.bgView.width - Border, 20);
    self.contentLab.frame = CGRectMake(self.tripImageView.left, self.tripImageView.bottom + 5, self.moneyLab.width, self.bgView.height - self.moneyLab.height - self.tripImageView.height - 20);
}

- (void)setModelData:(XXTripModelData *)modelData{
    _modelData = modelData;
    [self.tripImageView sd_setImageWithURL:[NSURL URLWithString:modelData.pic]];
    self.locationLab.text = modelData.address;
    self.contentLab.text = modelData.title;
    self.moneyLab.text = [NSString stringWithFormat:@"￥%@", modelData.price];
    [self.orderBtn setTitle:modelData.is_sign forState:UIControlStateNormal];
    self.tid = modelData.tid;
}

- (void)deleteBtnClick{
    NSLog(@"删除");
    if (self.block) {
        self.block();
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
